package com.juneng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juneng.common.R;
import com.juneng.config.PageResult;
import com.juneng.utils.Func;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.juneng.entity.CourseList;
import com.juneng.dto.CourseListDto;
import com.juneng.dto.CourseListQueryDto;
import com.juneng.vo.CourseListVo;
import com.juneng.service.ICourseListService;

/**
 * 课程目录 控制器
 *
 * @author zds
 * @since 2021-07-08
 */
@RestController
@AllArgsConstructor
@RequestMapping("courseList/v1")
@Api(tags = "课程目录相关接口")
public class CourseListController {

    private ICourseListService courseListService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperation(value = "详情", notes = "传入id")
    public R<CourseList> detail(Integer id) {
        CourseList detail = courseListService.getById(id);
        return R.success(detail);
    }

    /**
     * 分页 课程目录 hidden  component
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页", notes = "传入courseList")
    public R<IPage<CourseListVo>> page(CourseListQueryDto dto) {
        IPage<CourseListVo> pages = courseListService.page(dto);
        return R.success(pages);
    }

    /**
     * 列表 课程目录
     */
    @GetMapping("/list")
    @ApiOperation(value = "不分页", notes = "传入courseList")
    public R<List<CourseList>> list(CourseListQueryDto dto) {
        List<CourseList> list = courseListService.list(dto);
        return R.success(list);
    }

    /**
     * 新增 课程目录
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "传入courseList")
    public R save(@RequestBody CourseListDto dto) {
        return R.success(courseListService.save(dto));
    }

    /**
     * 修改 课程目录
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改", notes = "传入courseList")
    public R update(@RequestBody CourseListDto dto) {
        return R.success(courseListService.updateById(dto));
    }

    /**
     * 删除 课程目录
     */
    @DeleteMapping("/remove")
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.success(courseListService.deleteLogic(Func.toIntList(ids)));
    }
}
